import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';
import {HttpService} from './HttpService';

/*
  Generated class for the AMapService provider.

  See https://angular.io/docs/ts/latest/guide/dependency-injection.html
  for more info on providers and Angular 2 DI.
*/
@Injectable()
export class WebApiService {

    private static amap_key: string = 'e00ce7de01e3d5945a81c98f27e342de';
    private static jisuapi_appkey: string = '407a377bebf08309';
    private static showapi_appid: string = '40863';
    private static showapi_secret: string = 'fd0b7d0beca84ec5b5c6f95f65095661';

    constructor(private httpService: HttpService) {
        console.log('Hello AMapService Provider');
    }

    getAMapRegeo(longitude, latitude) {
        return this.httpService.instance()
            .setPath('http://restapi.amap.com/v3/geocode/regeo')
            .setQuery({
                key: WebApiService.amap_key,
                location: longitude + ',' + latitude
            })
            .getRequest();
    }

    getAMapDistrict(_subdistrict: number) {
        return this.httpService.instance()
            .setPath('http://restapi.amap.com/v3/config/district')
            .setQuery({
                key: WebApiService.amap_key,
                subdistrict: _subdistrict
            })
            .getRequest();
    }

    searchAMapDistrict(_keywords: string) {
        return this.httpService.instance()
            .setPath('http://restapi.amap.com/v3/config/district')
            .setQuery({
                key: WebApiService.amap_key,
                keywords: _keywords
            })
            .getRequest();
    }

    getJiSuApiNews(_channel: string, _start: number, _num: number) {
        return this.httpService.instance()
            .setPath('http://api.jisuapi.com/news/get')
            .setQuery({
                appkey: WebApiService.jisuapi_appkey,
                channel: _channel,
                start: _start,
                num: _num
            })
            .getRequest();
    }

    getShowApiNewsChannel() {
        return this.httpService.instance()
            .setPath('http://route.showapi.com/109-34')
            .setQuery({
                showapi_appid: WebApiService.showapi_appid,
                showapi_sign: WebApiService.showapi_secret
            })
            .getRequest();
    }

    getShowApiCaiJingNews(start, size, query?: any) {
        return this.httpService.instance()
            .setPath('http://route.showapi.com/109-35')
            .setQuery({
                showapi_appid: WebApiService.showapi_appid,
                showapi_sign: WebApiService.showapi_secret,
                channelId: '5572a108b3cdc86cf39001d0',
                channelName: null,
                title: null,
                page: start,
                needContent: 0,
                needHtml: 0,
                needAllList: 1,
                maxResult: size
            })
            .getRequest();
    }

    getShowApiLiCaiNews(start, size) {
        return this.httpService.instance()
            .setPath('http://route.showapi.com/109-35')
            .setQuery({
                showapi_appid: WebApiService.showapi_appid,
                showapi_sign: WebApiService.showapi_secret,
                channelId: '5572a109b3cdc86cf39001e1',
                channelName: null,
                title: null,
                page: start,
                needContent: 0,
                needHtml: 0,
                needAllList: 1,
                maxResult: size
            })
            .getRequest();
    }
}
